package com.drinks.yiniang.adapter.user.winelist;

import android.content.Context;
import android.media.audiofx.DynamicsProcessing;
import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseViewHolder;
import com.drinks.yiniang.R;
import com.drinks.yiniang.adapter.base.BaseQuickRCVAdapter;
import com.drinks.yiniang.entity.goods.GoodsJson;
import com.drinks.yiniang.entity.user.wine.WineListDetailJson;
import com.drinks.yiniang.entity.user.wish.DrinksWishJson;
import com.drinks.yiniang.ui.widget.textview.TagTextView;
import com.drinks.yiniang.utils.GlideUtils;
import com.hansen.library.ui.widget.image.RatioRoundImageView;
import com.hansen.library.ui.widget.layout.AutoLineFeedLayout;
import com.hansen.library.utils.CommonUtils;
import com.hansen.library.utils.StringUtils;

import java.util.List;

/**
 * 酒单详情页adapter
 *
 * @author han
 * @date 2019/8/30
 */
public class WineListDetailAdapter extends BaseQuickRCVAdapter<WineListDetailJson.WineListDetailGoods, BaseViewHolder> {

    private TagTextView mTagTextView;

    private StringBuilder mBuilder;

    public WineListDetailAdapter(Context mContext, @Nullable List<WineListDetailJson.WineListDetailGoods> data) {
        super(R.layout.item_wine_list_detail, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, WineListDetailJson.WineListDetailGoods item) {
        //编号
        int pos = helper.getAdapterPosition();
        helper.setText(R.id.tv_wld_number, helper.getAdapterPosition() < 10 ? "0" + pos : String.valueOf(pos));
        //商封面
        GlideUtils.loadSquareImage(mContext, (RatioRoundImageView) helper.getView(R.id.iv_wld_goods_cover), item.getCover_url());
        //标签
        //活动tag
        addLabelTag((AutoLineFeedLayout) helper.getView(R.id.ll_wld_goods_label), item.getActivity());
        //商品名称
        helper.setText(R.id.tv_wld_goods_name, item.getName());
        //推荐语
        helper.setText(R.id.tv_wld_goods_slogan, item.getRecommend_reason());
        //价格
        mBuilder = new StringBuilder("¥");
        mBuilder.append(StringUtils.getNullEmptyConvert__(item.getApp_price()));
        helper.setText(R.id.tv_wld_goods_price, mBuilder);
        //加入理由
        if(!StringUtils.isEmpty(item.getJoin_reason())) {
            helper.setGone(R.id.tv_wld_comment, true);
            helper.setText(R.id.tv_wld_comment, item.getJoin_reason());
        } else {
            helper.setGone(R.id.tv_wld_comment, false);
        }

        helper.addOnClickListener(R.id.tiv_wld_goods_add_cart);
    }

    private void addLabelTag(AutoLineFeedLayout layout, List<GoodsJson.GoodsActivity> actList) {
        layout.removeAllViews();

        if (CommonUtils.isEmptyList(actList)) {
            layout.setVisibility(View.GONE);

            return;
        }

        layout.setVisibility(View.VISIBLE);

        for (GoodsJson.GoodsActivity data : actList) {
            mTagTextView = new TagTextView(mContext);

            mTagTextView.setTagColor(data.getTag_color());
            mTagTextView.setText(data.getTag_name());

            layout.addView(mTagTextView);
        }
    }
}
